package com.fengye.serialization.common;


import org.apache.commons.lang.StringUtils;

/**
 * @Author fengye
 * @Date 2023/2/12 11:43
 **/
public enum SerializeType {

    /** java 默认序列化 */
    DEFAULT_JAVA("DefaultJavaSerializer"),
    HESSIAN("HessianSerializer"),

    HESSIAN2("Hessian2Serializer"),

    FASTJSON("FASTJSONSerializer"),

    JSON("JSONSerializer"),

    XML("XmlSerializer"),

    PROTOSTUFF("ProtoStuffSerializer"),

    MARSHALLING("MarshallingSerializer")
    ;


    /** 序列化类型 */
    private String serializeType;

    private SerializeType(String serializeType) {
        this.serializeType = serializeType;
    }

    public String getSerializeType() {
        return serializeType;
    }

    /**
     * 根据serializeType查询SerializeType
     *
     * @param serializeType
     * @return
     */
    public static SerializeType queryByType(String serializeType) {
        if(StringUtils.isEmpty(serializeType)){
            return null;
        }

        for (SerializeType serialize : SerializeType.values()) {
            if(StringUtils.equals(serializeType, serialize.getSerializeType())) {
                return serialize;
            }
        }
        return null;
    }
}
